package com.iss.efi.service.impl;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iss.efi.dto.Efi078;
import com.iss.efi.dto.ReceiveDto;
import com.iss.efi.dto.ResultDto;
import com.iss.efi.service.Efi078Service;
import com.iss.efi.mapper.Efi078Mapper;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author songyong
* @description 针对表【EFI078】的数据库操作Service实现
* @createDate 2024-02-02 15:50:21
*/
@Service
public class Efi078ServiceImpl extends ServiceImpl<Efi078Mapper, Efi078>
    implements Efi078Service{

    @Resource
    private SqlSessionFactory sqlSessionFactory;

    @Override
    public List<Efi078> getListByGys(JSONObject param) {
        return  this.getBaseMapper().getListByGys(param);

    }

    @Override
    public ResultDto confirm(JSONObject param) {
        ResultDto resultDto=new ResultDto("00","操作成功");
        String vendor=param.getString("VENDOR");
        String ids=param.getString("IDS");
        SqlSession batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
        try {
            Efi078Mapper efi078Mapper=  batchSqlSession.getMapper(Efi078Mapper.class);
            for (String id:ids.split(",")){
                 Map<String,String> params= new HashMap<>();
                 params.put("vendor",vendor);
                 params.put("id",id);
                efi078Mapper.updateState(params);
            }
            batchSqlSession.commit();
        } catch (Exception e) {
            e.printStackTrace();
            batchSqlSession.rollback();
            return new ResultDto("E03","保存数据出错");
        } finally {
            batchSqlSession.close();
        }
        return resultDto;
    }

    @Override
    public List<ReceiveDto> getReceiveNum(JSONObject param) {

        List<ReceiveDto> params=new ArrayList<>();

        params= param.getList("list",ReceiveDto.class);

        List<ReceiveDto>  res=  this.getBaseMapper().getReceiveNum(params);
        return res;
    }


}




